package com.aaa.car.controller;

import com.aaa.car.service.CarCommentService;
import com.aaa.common.entity.CarComment;
import com.github.pagehelper.PageInfo;
import com.aaa.common.util.Result;
import com.aaa.common.util.ResultStatus;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (CarComment)表控制层
 *
 * @author lei chu
 * @since 2021-02-20 16:32:18
 */
@RestController
@RequestMapping("carComment")
@ApiOperation("carComment控制器")
public class CarCommentController {
    /**
     * 服务对象
     */
    @Resource
    private CarCommentService carCommentService;

    /**
     * 通过实体作为筛选条件查询
     *
     * @param pageNum    当前页数
     * @param pageSize   每页条数
     * @param carComment 实例对象
     * @return 分页数据和信息
     */
    @PostMapping("queryAll")
    public Result<PageInfo<CarComment>> queryAll(Integer pageNum, Integer pageSize, @RequestBody CarComment carComment) {
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.carCommentService.queryAll(pageNum, pageSize, carComment));
    }

    /**
     * 新增数据
     *
     * @param carComment 实例对象
     * @return 实例对象
     */
    @PostMapping("insert")
    public Result<CarComment> insert(@RequestBody CarComment carComment) {
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.carCommentService.insert(carComment));
    }

    /**
     * 修改数据
     *
     * @param carComment 实例对象
     * @return 实例对象
     */
    @PutMapping("update")
    public Result<CarComment> update(@RequestBody CarComment carComment) {
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.carCommentService.update(carComment));
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @DeleteMapping("delete/{id}")
    public Result<Boolean> deleteById(@PathVariable("id") Integer id) {
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.carCommentService.deleteById(id));
    }
}